<?php
/**
 * 日志记录
 * Created by PhpStorm.
 * User: crstu
 * Date: 2016/4/27
 * Time: 10:54
 */

use kartik\grid\GridView;
use common\widgets\Box;
use kartik\export\ExportMenu;

Box::begin();

$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    [
        'attribute' => 'adminID',
        'label' => '管理员',
        'value' => function($model){
            return $model->admin->realName;
        }
    ],
    [
        'attribute' => 'type',
        'label' => '类型',
        'filter' => [
            'LOGIN' => '登陆'
        ]
    ],
    'controller',
    'action',
    'result',
    'createIP',
    [
        'format'=>'datetime',
        'attribute'=>'createTime',
        'filterType' => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => [
            'presetDropdown' => true,
            'pluginOptions' => [
                'format' => 'YYYY-MM-DD',
                'separator' => ' ~ ',
                'language'=>'zh-CN',
            ],
            'pluginEvents' => [
                "apply.daterangepicker" => "function(){ aplicarDateRangeFilter('createTime') }",
            ],
        ],
    ],
    'param'
];

$fullExportMenu = ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'target' => ExportMenu::TARGET_BLANK,
    'fontAwesome' => true,
    'dropdownOptions' => [
        'label' => '全部',
        'class' => 'btn btn-default',
        'itemsBefore' => [
            '<li class="dropdown-header">导出全部数据</li>',
        ],
    ],
]);

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel'=>$searchModel,
    'columns' => $gridColumns,
    'toolbar'=> [
        $fullExportMenu,
        '{toggleData}',
    ],
    'panel' => [
        'type' => GridView::TYPE_PRIMARY,
        'heading' => '筛选结果',
    ],
]);